﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Artizan.Utility;

/// <summary>
/// Summary description for PropertyAttribute
/// </summary>
public class PropertyAttribute
{
    public int PomplingAddressID { get; set; }
    public string LookupText { get; set; }
    public string AttributeDescription { get; set; }
    public int Displayposition { get; set; }

    public static void AddAttribute(Lookup lookup, int pomplingAddressID, string attributeDescription)
    {
        using (SqlConnection conn = new SqlConnection(Globals.GetConnectionString()))
        {
            using (SqlCommand cmd = new SqlCommand("PomPropertyAttributesSave", conn))
            {
                try
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@pPomplingAddressID", pomplingAddressID);
                    cmd.Parameters.AddWithValue("@pLookupID", lookup.LookupID);
                    cmd.Parameters.AddWithValue("@pLookupText", lookup.LookupText);
                    cmd.Parameters.AddWithValue("@pAttributeDescription", attributeDescription);
                    //cmd.Parameters.AddWithValue("@pDisplayposition", 4);
                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
                catch (Exception en)
                {
                    throw en;
                }
            }
        }
    }

    public static List<PropertyAttribute> SelectpropertyAttributes( int addressID)
    {
        string connectionString = Globals.GetConnectionString();
        List<PropertyAttribute> propertiesList = new List<PropertyAttribute>();
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            using (SqlCommand cmd = new SqlCommand("PomSelectPropertyAttributes", conn))
            {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pPomplingAddressID", addressID);
                cmd.Connection.Open();

                DataTable dt = new DataTable("DtPropertyAttList");
                IDataReader reader = cmd.ExecuteReader();
                dt.Load(reader);
                cmd.Connection.Close();
                propertiesList = FieldMapper.DataTableToList<PropertyAttribute>(ref dt);
            }
        }
        return propertiesList;
    }



    //public static List<PropertyAttribute> SelectpropertyAttributes(string connectionString, int webPropertyID)
    //{
    //    List<PropertyAttribute> propertiesList = new List<PropertyAttribute>();
    //    using (SqlConnection conn = new SqlConnection(connectionString))
    //    {
    //        using (SqlCommand cmd = new SqlCommand("SelectPropertyAttributes", conn))
    //        {
    //            cmd.CommandType = System.Data.CommandType.StoredProcedure;
    //            cmd.Parameters.AddWithValue("@pWebPropertyID", webPropertyID);
    //            cmd.Connection.Open();

    //            DataTable dt = new DataTable("DtPropertyAttList");
    //            IDataReader reader = cmd.ExecuteReader();
    //            dt.Load(reader);
    //            cmd.Connection.Close();
    //            propertiesList = FieldMapper.DataTableToList<PropertyAttribute>(ref dt);
    //        }
    //    }
    //    return propertiesList;
    //}

    public static void Delete(int pomplingAddressID)
    {
        using (SqlConnection conn = new SqlConnection(Globals.GetConnectionString()))
        {
            using (SqlCommand cmd = new SqlCommand("PomPropertyAttributesDelete", conn))
            {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pPomplingAddressID", pomplingAddressID);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }
    }
}